﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Interactivity;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Data;

namespace nRoute.Behaviors.Interactivity
{
    public abstract class TriggerAction
        : AttachableDependencyObject
    {
        public static readonly DependencyProperty IsEnabledProperty =
            DependencyProperty.Register("IsEnabled", typeof(bool), typeof(TriggerAction),
            new PropertyMetadata(true));

        [Category("Common Properties")]
        public bool IsEnabled
        {
            get { return Convert.ToBoolean(GetValue(IsEnabledProperty)); }
            set { SetValue(IsEnabledProperty, value); }
        }

        [Category("Common Properties")]
        [CustomPropertyValueEditor(CustomPropertyValueEditor.PropertyBinding)]
        public Binding IsEnabledBinding
        {
            get { return GetBinding(IsEnabledProperty); }
            set { SetBinding<bool>(IsEnabledProperty, value); }
        }

        internal void InvokeInternal(object parameter)
        {
            if (this.IsEnabled) Invoke(parameter);
        }

        protected abstract void Invoke(object parameter);
    }
}
